/**
 *
 * @version   1.0 2016/9/5
 * @author    黄坚：huangjian@sunmnet.com
 * @since     jdk版本：jdk1.7
 */
var createCol = function () {
	var grid_selector = "#grid-table";
	var showSelector = '#showCol';
	return {
	//{name:'name',index:'name', width:120,editable: true,editoptions:{size:"20",maxlength:"30"}},
		join: function (conf) {
			var str = '';
			var arr = [];
			if (conf['index']) {
				arr.push('name: "' + conf['index'] + '"');
				arr.push('index: "' + conf['index'] + '"');
			}

			if (conf['hidden']) {
				arr.push('hidden: ' + conf['hidden']);
			}

			if (conf['align']) {
				arr.push('align: "' + conf['align'] + '"');
			}

			if (conf['width']) {
				arr.push('width: ' + conf['width']);
			}

			if (conf['sorttype']) {
				arr.push('sorttype: "' + conf['sorttype'] + '"');
			}

			if (conf['editable']) {
				arr.push('editable: ' + conf['editable']);
			}

			if (conf['edittype']) {
				arr.push('edittype: "' + conf['edittype'] + '"');
			}



			if (conf['editoptions'] || conf['editoptions'] == ''){
				arr.push('editoptions:{value:"'+conf['editoptions']+'"');

				if (conf['editoptions-size'])
					arr.push('size:"'+conf['editoptions-size']+'"');
				if (conf['editoptions-maxlength'])
					arr.push('maxlength:"'+conf['editoptions-maxlength']+'"');
				if (conf['editoptions-rows'])
					arr.push('rows:"'+conf['editoptions-rows']+'"');
				if (conf['editoptions-cols'])
					arr.push('cols:"'+conf['editoptions-cols']+'"');
			}



			if (conf['unformat']) {
				arr.push('unformat: ' + conf['unformat']);
			}


			$(showSelector).append('{' + arr.join(',') + '}},');
		},

		create: function () {

			var obj = $(grid_selector).jqGrid("getRowData");
			$.each(obj, function(idx, val) {
				createCol.join(val);
				$(showSelector).append('<h6>');

			});
			$('#showCol').append('<h6>***************************<h6>');
		},


		del: function () {
			var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
			// 根据id获取选中行数据
			var resData = $(grid_selector).jqGrid('getRowData', id);
			// 判断是否选中
			if (sUtils.isNull(id)) {
				layer.alert('请选择要删除的行数！', {icon: 5, title: '提示'});
				return;
			}

			layer.confirm('确定要删除吗？', {icon: 3, title: '提示'}, function (index) {
				/*var delUrl = url + resData.id;
				sPost.ajaxDel(delUrl, {}, function (data) {
					if (data.success) {
						slog.log("Delete 成功！");
						layer.alert('删除成功！', {icon: 1, title: '提示'});
					} else {
						slog.error("Delete Error : " + data.msg);
					}
				});*/
				layer.alert('删除成功！', {icon: 1, title: '提示'});
				$(grid_selector).jqGrid('delRowData', id);
				layer.close(index);
			});
		},

		add: function () {
			var params = sUtils.getFormParams();
			/*var params = sUtils.getFormParams();
			sPost.ajax(url, params, function (data) {
				if (data.success) {
					slog.log("Add Method 成功！");
					slog.log(data);
					params = data;
					layer.alert('保存成功！', {icon: 1, title: '提示'});
				} else {
					slog.error("Add Method 失败 : " + data.msg);
				}
			});
			slog.log(params);*/
			$(grid_selector).jqGrid('addRowData', 0, params, 'first');
		}


	}
} ();